<?php

namespace app\daili\controller;
use think\facade\Db;

class Login extends  Base

{
    public function initialize() {
        
        //已登录直接跳转
        $account = session('dailiAccount');
        if($account && $account['id']) {
           header('Location: /daili/index');

        }
    }

    //后台登录的逻辑
	public function index()

    {
      
        if(request()->isPost()) {

            $data = input('post.');
            


            // 通过用户名 获取 用户相关信息

            $adminData = Db::name('daili')->where('username',$data['username'])->find();//一维数组


            // if(!$adminData || $adminData['status'] !=1 ) {

            //     return alert('此代理用户未被审核通过或已被封禁');

            // }




            if($adminData['userpass'] !=$this->password_salt($data['userpass'])) {
                return alert('密码不正确','/daili/index',5,3);
            }

            session('dailiAccount', $adminData);
            
            return alert('登录成功！','/daili/index',6,3);


        }else {

            
            return view();

        }

    }
  public function logout() {

      // 清除session
      session(null);

      // 跳出
      return redirect('/daili/index');

  }
    

}